function changeTheme() {
	var tema = document.getElementsByName("tema")[0];
	if(tema.options[tema.selectedIndex].value == "klasik") {
		var cssfile = document.getElementById("cssfile");
		cssfile.setAttribute("href","style1.css");
	} else if(tema.options[tema.selectedIndex].value == "pelangi"){
		var cssfile = document.getElementById("cssfile");
		cssfile.setAttribute("href","style2.css");
	}
}

function parseDate(date) {
	//Tue Mar 06 2012 08:12:27 GMT+0700 (SE Asia Standard Time)
	ret = "";
	temp = [];
	temp = date.split(' ');
	ret += temp[2] + " ";
	ret += temp[1] + " ";
	ret += temp[3];
	ret += " at ";
	ret += temp[4].substring(0, 5);
	return ret;
}

function validateComment() {
	if(document.getElementById("content-input-comment").value.toString() == "") {
		alert("Comment box can't be empty!");
		return false;
	}
	return true;
}


function addComment(str, post_id, user_id) {
	var xmlhttp;	
	//lolos validasi
	if (window.XMLHttpRequest){
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) {		
			//cek apakah error inserting comment 
			var temp = xmlhttp.responseText.split(/[\s]+/);			
			if(temp[0]=="error") {				
				document.getElementById("comment-content-error").innerHTML = xmlhttp.responseText.substring(temp[0].length);
			}else{	
				//berhasil														
				
				var cont = document.getElementById('content-comments');
				document.getElementById("content-input-comment").value="";									
				cont.innerHTML=xmlhttp.responseText;						
				
				//tambah comment-count secara ajax		
					
				document.getElementById("comment-count").innerHTML = parseInt(document.getElementById("comment-count").innerHTML) + 1;
			}
		}
	}	
	
	xmlhttp.open("POST","ajax/content_response.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");	
	xmlhttp.send("q=add-comment&content="+str+"&post_id="+post_id+"&logged_in_user_id="+user_id);	
}

function delComment(comment_id) {
	var xmlhttp;

	//lolos validasi
	if (window.XMLHttpRequest){
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) {		
			//cek apakah error inserting comment 
			var temp = xmlhttp.responseText.split(/[\s]+/);			
			if(temp[0]=='error') {
				//error remove
				alert("i see what you did there");
			}else{				
				//berhasil remove								
				var removedComment = document.getElementById("comment"+xmlhttp.responseText);
				document.getElementById("content-comments").removeChild(removedComment);
				
				//kurangi comment-count secara ajax					
				document.getElementById("comment-count").innerHTML = parseInt(document.getElementById("comment-count").innerHTML) - 1;
			}			
		}
	}	
	
	xmlhttp.open("POST","ajax/content_response.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");	
	xmlhttp.send("q=del-comment&comment_id="+comment_id);	
}